package main

import (
	"context"
	"fmt"
	"time"

	clientv3 "go.etcd.io/etcd/client/v3"
)

func main() {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"10.0.0.11:2379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		// handle error!
		fmt.Println(err)
		return
	}
	defer cli.Close()
	// 用于读写etcd的键值对
	kv := clientv3.NewKV(cli)

	resp, err := kv.Delete(context.TODO(), "/home", clientv3.WithPrevKV(), clientv3.WithPrefix())
	if err != nil {
		fmt.Println(err)
		return
	}
	if resp.Deleted != 0 {
		for _, v := range resp.PrevKvs {
			fmt.Println("删除了: ", v)
		}
	} else {
		fmt.Println("no delet same one")
	}

}
